//
//  PaperDataViewManager.m
//  ZYOnlineSchool
//
//  Created by 毕武侠 on 2017/3/7.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "PaperDataViewManager.h"
#import "PaperModuleModel.h"

@interface PaperDataViewManager ()

@property (nonatomic,strong)NSMutableArray *array;

@end

@implementation PaperDataViewManager

- (void)setupConfigure {
    [super setupConfigure];
    
    @weakify(self)
    [self.receiveSignal subscribeNext:^(NSMutableArray *receive) {
        @strongify(self)
        if (![receive isKindOfClass:[NSMutableArray class]] || receive.count == 0) {
            return;
        }
        self.array = receive;
        if (self.receiveIndex == 0) {
            [self setupAnswerModel:receive];
        } else if (self.receiveIndex == 1) {
            [self setupModuleModel:receive];
        }
    }];
    
    [self setupLoadingView:self.superView];
}

#pragma mark - setter 

- (void)setupModuleModel:(NSMutableArray *)datas {
    [datas enumerateObjectsUsingBlock:^(PaperModuleModel *moduleModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [moduleModel.module_question enumerateObjectsUsingBlock:^(PaperBaseModel *answerModel, NSUInteger idx, BOOL * _Nonnull stop) {
            answerModel.identifier = self.paperIdentifier;
            answerModel.showPaperAnaly = self.showPaperAnaly;
            answerModel.showAnswerAnaly = self.showAnswerAnaly;
            answerModel.showKnowledge = self.showKnowledge;
            answerModel.showComment = self.showComment;
        }];
    }];
    
    self.paperDatas = datas;
}

- (void)setupAnswerModel:(NSMutableArray *)datas {

    PaperModuleModel *moduleModel = [[PaperModuleModel alloc] init];
    moduleModel.showModule = NO;
    moduleModel.identifier = @"PaperCollectionReusableViewID";
    moduleModel.question_number = [NSString stringWithFormat:@"%ld", datas.count];
    self.paperDatas = @[moduleModel].mutableCopy;
    [datas enumerateObjectsUsingBlock:^(PaperBaseModel *answerModel, NSUInteger idx, BOOL * _Nonnull stop) {
        answerModel.identifier = self.paperIdentifier;
        answerModel.showPaperAnaly = self.showPaperAnaly;
        answerModel.showAnswerAnaly = self.showAnswerAnaly;
        answerModel.showKnowledge = self.showKnowledge;
        answerModel.showComment = self.showComment;
    }];
    moduleModel.module_question = datas;
}

- (void)setPaperIdentifier:(NSString *)paperIdentifier{
    _paperIdentifier = paperIdentifier;
    if (self.receiveIndex == 0) {
//        [self setupAnswerModel:self.array];
    } else if (self.receiveIndex == 1) {
//        [self setupModuleModel:self.array];
    }

}

@end
